<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="author" content="esy">
    
    <meta name="description" content="esy">
    
    
    
    
    
    
    <title>python上的GUI | ESY</title>
    <link href="https://esyyes.github.io" rel="prefetch" />

    
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/aos.css">
<link rel="stylesheet" href="/css/style.css">

    
<script src="/js/jquery.min.js"></script>

    
<script src="/js/bootstrap.min.js"></script>

    
<script src="/js/aos.js"></script>

    
<script src="/js/highslide/highslide-full.min.js"></script>

    
<link rel="stylesheet" href="/js/highslide/highslide.css">

    <style type="text/css">
        @media (max-width: 768px) {
            body {
                background-color: #f0f0f0;
                background: url('/imgs/xsbg.gif');
                background-attachment: fixed;
            }
        }
    </style>
    
    <!--<script type="text/javascript">
      if (document.images) {
        var avatar = new Image();
        avatar.src = '/imgs/avatar.jpg'
        var previews = 'preview1.jpg,preview2.jpg,preview3.jpg,preview4.jpg'.split(',')
        var previewsPreLoad = []
        for(var i = 0; i < length; i++) {
          previewsPreLoad.push(new Image())
          previewsPreLoad[previewsPreLoad.length - 1].src = '/imgs/preview' + previews[i]
        }
      }
    </script>-->
<meta name="generator" content="Hexo 5.2.0"></head>
<body>
    <!-- 背景轮播图功能 -->
    <section class="hidden-xs">
    <ul class="cb-slideshow">
        <li><span>天若</span></li>
        <li><span>有情</span></li>
        <li><span>天亦老</span></li>
        <li><span>我为</span></li>
        <li><span>长者</span></li>
        <li><span>续一秒</span></li>
    </ul>
</section>
    <!-- 欧尼酱功能, 谁用谁知道 -->
    
    <div class="gal-menu gal-dropdown">
    <div class="circle" id="gal">
        <div class="ring">
            <a href="https://esyyes.github.io" class="menuItem" style="left: 50%; top: 15%;">首页</a>
            
            <a class="menuItem" style="left: 80.3109%; top: 32.5%;">下一页</a>
            
            <a href="/archives" class="menuItem" style="left: 80.3109%; top: 67.5%;">归档</a>
            <a href="/about" class="menuItem" style="left: 50%; top: 85%;">关于</a>
            <a href="/message" class="menuItem" style="left: 19.6891%; top: 67.5%;">留言板</a>

            
            <a class="menuItem" style="left: 19.6891%; top: 32.5%;">上一页</a>
            
        </div>
        <audio id="audio" src="/imgs/oni.mp3"></audio>
    </div>
</div>
    
    <header class="navbar navbar-inverse" id="gal-header">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target=".bs-navbar-collapse"
                    aria-expanded="false">
                <span class="fa fa-lg fa-reorder"></span>
            </button>
            <a href="https://esyyes.github.io">
                
                <style>
                    #gal-header .navbar-brand {
                        height: 54px;
                        line-height: 24px;
                        font-size: 28px;
                        opacity: 1;
                        background-color: rgba(0,0,0,0);
                        text-shadow: 0 0 5px #fff,0 0 10px #fff,0 0 15px #fff,0 0 20px #228DFF,0 0 35px #228DFF,0 0 40px #228DFF,0 0 50px #228DFF,0 0 75px #228DFF;
                    }
                </style>
                <!-- 这里使用文字(navbar_text or config.title) -->
                <div class="navbar-brand">ESY</div>
                
            </a>
        </div>
        <div class="collapse navbar-collapse bs-navbar-collapse">
            <ul class="nav navbar-nav" id="menu-gal">
                
                
                <li class="">
                    <a href="/">
                        <i class="fa fa-home"></i>首页
                    </a>
                </li>
                
                
                
                <li class="">
                    <a href="/archives">
                        <i class="fa fa-archive"></i>归档
                    </a>
                </li>
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-list"></i>分类
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/categories/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/categories/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/categories/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo%E5%AE%8C%E5%96%84/">-hexo完善</a>
                        </li>
                        
                        
                        <li>
                            <a href="/categories">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-tags"></i>标签
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/tags/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/tags/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/tags/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">-个人博客搭建</a>
                        </li>
                        
                        
                        <li>
                            <a href="/tags">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                <li class="">
                    <a href="/about">
                        <i class="fa fa-user"></i>关于我
                    </a>
                </li>
                
                
            </ul>
        </div>
    </div>
</header>
    <div id="gal-body">
        <div class="container">
            <div class="row">
                <div class="col-md-8 gal-right" id="mainstay">
                    
<article class="article well article-body" id="article">
    <div class="breadcrumb">
        <i class="fa fa-home"></i>
        <a href="https://esyyes.github.io">ESY</a>
        >
        <span>python上的GUI</span>
    </div>
    <!-- 大型设备详细文章 -->
    <div class="hidden-xs">
        <div class="title-article">
            <h1>
                <a href="/2020/07/21/python%20work/python%E4%B8%8A%E7%9A%84GUI/">python上的GUI</a>
            </h1>
        </div>
        <div class="tag-article">
            
            <span class="label label-gal">
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
            </span>
            
            <span class="label label-gal">
                <i class="fa fa-calendar"></i> 2020-07-21
            </span>
            
        </div>
    </div>
    <!-- 小型设备详细文章 -->
    <div class="visible-xs">
        <center>
            <div class="title-article">
                <h4>
                    <a href="/2020/07/21/python%20work/python%E4%B8%8A%E7%9A%84GUI/">python上的GUI</a>
                </h4>
            </div>
            <p>
                <i class="fa fa-calendar"></i> 2020-07-21
            </p>
            <p>
                
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
                
                
            </p>
        </center>
    </div>
    <div class="content-article">
        <h1 id="Python-GUI编程-Tkinter"><a href="#Python-GUI编程-Tkinter" class="headerlink" title="Python GUI编程(Tkinter)"></a>Python GUI编程(Tkinter)</h1><h2 id="tkinter介绍"><a href="#tkinter介绍" class="headerlink" title="tkinter介绍"></a>tkinter介绍</h2><p><a target="_blank" rel="noopener" href="https://www.runoob.com/python/python-gui-tkinter.html">https://www.runoob.com/python/python-gui-tkinter.html</a></p>
<p>这个链接里面直接设置相关的</p>
<p>Python 提供了多个图形开发界面的库，几个常用 Python GUI 库如下： </p>
<ul>
<li><strong>Tkinter：</strong> Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 .Tk 和 Tkinter 可以在大多数的 Unix 平台下使用,同样可以应用在 Windows 和 Macintosh 系统里。Tk8.0 的后续版本可以实现本地窗口风格,并良好地运行在绝大多数平台中。</li>
<li><strong>wxPython：</strong>wxPython 是一款开源软件，是 Python 语言的一套优秀的 GUI 图形库，允许 Python 程序员很方便的创建完整的、功能健全的 GUI 用户界面。</li>
<li><strong>Jython：</strong>Jython 程序可以和 Java 无缝集成。除了一些标准模块，Jython 使用 Java 的模块。Jython 几乎拥有标准的Python 中不依赖于 C 语言的全部模块。比如，Jython 的用户界面将使用  Swing，AWT或者 SWT。Jython 可以被动态或静态地编译成 Java 字节码。</li>
</ul>
<p>Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。</p>
<p>由于 Tkinter 是内置到 python 的安装包中、只要安装好 Python 之后就能 import Tkinter 库、而且 IDLE 也是用 Tkinter 编写而成、对于简单的图形界面 Tkinter 还是能应付自如。</p>
<p>*<em>注意**</em>：Python3.x 版本使用的库名为 tkinter,即首写字母 T 为小写。*</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tkinter</span><br></pre></td></tr></table></figure>

<p>创建一个GUI程序</p>
<ul>
<li>1、导入 Tkinter 模块</li>
<li>2、创建控件</li>
<li>3、指定这个控件的 master， 即这个控件属于哪一个</li>
<li>4、告诉 GM(geometry manager) 有一个控件产生了。</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tkinter</span><br><span class="line">创建简单窗口</span><br><span class="line">top = tkinter.Tk()</span><br><span class="line"><span class="comment"># 进入消息循环</span></span><br><span class="line">top.mainloop()</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/7/21</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建窗口</span></span><br><span class="line">root = thinter.TK()</span><br><span class="line">root = Tk()</span><br><span class="line"><span class="comment"># 标题</span></span><br><span class="line">root.title(<span class="string">&#x27;Q&amp;A chatbot&#x27;</span>)</span><br><span class="line"><span class="comment"># 窗口大小 小写的x，表示大小</span></span><br><span class="line">root.geometry(<span class="string">&#x27;720x400+500+200&#x27;</span>)</span><br><span class="line"><span class="comment"># 窗口位置 像素px  的坐标。距离左上角的位置</span></span><br><span class="line"><span class="comment"># root.geometry(&#x27;+500+300&#x27;)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 标签控件</span></span><br><span class="line">label = Label(root, text=<span class="string">&#x27;签名&#x27;</span>, font=(<span class="string">&#x27;华为行楷&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;red&#x27;</span>)</span><br><span class="line"><span class="comment"># pack place 定位（只用一种）grid 网格布局</span></span><br><span class="line">label.grid()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输入框</span></span><br><span class="line">entry = Entry(root, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>))</span><br><span class="line"><span class="comment"># row对应行，column对应的列</span></span><br><span class="line">entry.grid(row=<span class="number">0</span>, column=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 点击按钮</span></span><br><span class="line">button = Button(root, text=<span class="string">&#x27;设计签名&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line"><span class="comment"># 宽高设置</span></span><br><span class="line">button[<span class="string">&#x27;width&#x27;</span>] = <span class="number">10</span></span><br><span class="line">button[<span class="string">&#x27;height&#x27;</span>] = <span class="number">1</span></span><br><span class="line"><span class="comment"># 对齐方式sticky,W左。E右, stick=E</span></span><br><span class="line">button.grid(row=<span class="number">1</span>, column=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 消息循环 显示窗口</span></span><br><span class="line">root.mainloop()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>组件：按钮，文本输入框。滚动条等</p>
<p>窗口：root输入</p>
<h2 id="GUI–窗口设置"><a href="#GUI–窗口设置" class="headerlink" title="GUI–窗口设置"></a>GUI–窗口设置</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tkinter</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建主窗口对象</span></span><br><span class="line">root = tkinter.Tk()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 给窗口加入标题</span></span><br><span class="line">root.title(<span class="string">&#x27;Q&amp;A chatbot&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置窗口大小,像素大小</span></span><br><span class="line"><span class="comment"># root.minsize(300, 300)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 窗口大小 小写的x，表示大小， 和位置</span></span><br><span class="line">root.geometry(<span class="string">&#x27;720x400+500+200&#x27;</span>)</span><br><span class="line"><span class="comment"># 窗口位置 像素px  的坐标。距离左上角的位置</span></span><br><span class="line"><span class="comment"># root.geometry(&#x27;+500+300&#x27;)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 加入信息循环</span></span><br><span class="line">root.mainloop()</span><br></pre></td></tr></table></figure>

<h2 id="组件摆放方式"><a href="#组件摆放方式" class="headerlink" title="组件摆放方式"></a>组件摆放方式</h2><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/myshuzhimei/p/11764532.html">https://www.cnblogs.com/myshuzhimei/p/11764532.html</a></p>
<p><strong>Tkinter之部件3种放置方式pack、grid、place</strong></p>
<p>以规律的方格形式呈现。比如下面的代码就是创建一个三行三列的表格：参数row 为行，colum 为列，padx 单元格左右间距，pady单元格上下间距，ipadx单元格内部元素与单元格的左右间距，ipady单元格内部元素与单元格的上下间距。</p>
<p>直接用grid方式</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/7/21</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> tkinter</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建主窗口对象</span></span><br><span class="line">root = tkinter.Tk()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 给窗口加入标题</span></span><br><span class="line">root.title(<span class="string">&#x27;Q&amp;A chatbot&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置窗口大小,像素大小</span></span><br><span class="line"><span class="comment"># root.minsize(300, 300)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 窗口大小 小写的x，表示大小， 和位置</span></span><br><span class="line">root.geometry(<span class="string">&#x27;720x400+500+200&#x27;</span>)</span><br><span class="line"><span class="comment"># 窗口位置 像素px  的坐标。距离左上角的位置</span></span><br><span class="line"><span class="comment"># root.geometry(&#x27;+500+300&#x27;)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 点击按钮</span></span><br><span class="line">button = tkinter.Button(root, text=<span class="string">&#x27;点击0&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button.grid(row=<span class="number">0</span>, column=<span class="number">0</span>)</span><br><span class="line">button1 = tkinter.Button(root, text=<span class="string">&#x27;点击1&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button1.grid(row=<span class="number">0</span>, column=<span class="number">1</span>)</span><br><span class="line">button2 = tkinter.Button(root, text=<span class="string">&#x27;点击2&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button2.grid(row=<span class="number">1</span>, column=<span class="number">0</span>)</span><br><span class="line">button3 = tkinter.Button(root, text=<span class="string">&#x27;点击3&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button3.grid(row=<span class="number">1</span>, column=<span class="number">1</span>)</span><br><span class="line">button4 = tkinter.Button(root, text=<span class="string">&#x27;点击4&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button4.grid(row=<span class="number">2</span>, column=<span class="number">0</span>, columnspan=<span class="number">2</span>, ipadx=<span class="number">40</span>)</span><br><span class="line">button5 = tkinter.Button(root, text=<span class="string">&#x27;点击5&#x27;</span>, font=(<span class="string">&#x27;微软雅黑&#x27;</span>, <span class="number">20</span>), fg=<span class="string">&#x27;blue&#x27;</span>)</span><br><span class="line">button5.grid(row=<span class="number">0</span>, column=<span class="number">2</span>, rowspan=<span class="number">2</span>, ipady=<span class="number">40</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 跨列columnspan rowspan,跨行</span></span><br><span class="line"><span class="comment"># ipadx,ipady 跨距离设置</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 加入信息循环</span></span><br><span class="line">root.mainloop()</span><br></pre></td></tr></table></figure>

<h2 id="组件信息"><a href="#组件信息" class="headerlink" title="组件信息"></a>组件信息</h2><h1 id="鼠标样式"><a href="#鼠标样式" class="headerlink" title="鼠标样式"></a>鼠标样式</h1><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root[<span class="string">&#x27;cursor&#x27;</span>] = <span class="string">&#x27;heart&#x27;</span></span><br></pre></td></tr></table></figure>



<h3 id="cheakbutoon勾选框组件"><a href="#cheakbutoon勾选框组件" class="headerlink" title="cheakbutoon勾选框组件"></a>cheakbutoon勾选框组件</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/7/21</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> tkinter</span><br><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建主窗口对象</span></span><br><span class="line">root = tkinter.Tk()</span><br><span class="line"><span class="comment"># 鼠标样式</span></span><br><span class="line">root[<span class="string">&#x27;cursor&#x27;</span>] = <span class="string">&#x27;heart&#x27;</span></span><br><span class="line"><span class="comment"># 给窗口加入标题</span></span><br><span class="line">root.title(<span class="string">&#x27;Q&amp;A chatbot&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置窗口大小,像素大小</span></span><br><span class="line"><span class="comment"># root.minsize(300, 300)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 窗口大小 小写的x，表示大小， 和位置</span></span><br><span class="line">root.geometry(<span class="string">&#x27;720x400+500+200&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># cheakbutton 选择框组件</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果文本的内容有变化</span></span><br><span class="line">text = tkinter.StringVar()</span><br><span class="line">text.<span class="built_in">set</span>(<span class="string">&#x27;同意&#x27;</span>)</span><br><span class="line"><span class="comment"># 设置选择框钩与不钩的值</span></span><br><span class="line">result = tkinter.IntVar()</span><br><span class="line"><span class="comment"># 设置返回值</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>():</span></span><br><span class="line">    print(result.get())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">cheakbutoon = tkinter.Checkbutton(root, textvariable=text, variable=result, command=func)</span><br><span class="line">cheakbutoon.grid(row=<span class="number">0</span>, column=<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 加入信息循环</span></span><br><span class="line">root.mainloop()</span><br></pre></td></tr></table></figure>



<h1 id="输入组件"><a href="#输入组件" class="headerlink" title="输入组件"></a>输入组件</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"># @Time     : 2020&#x2F;7&#x2F;21</span><br><span class="line"># @Author   : esy</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">import tkinter</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 创建主窗口对象</span><br><span class="line">root &#x3D; tkinter.Tk()</span><br><span class="line"># 鼠标样式</span><br><span class="line">root[&#39;cursor&#39;] &#x3D; &#39;heart&#39;</span><br><span class="line"># 给窗口加入标题</span><br><span class="line">root.title(&#39;Q&amp;A chatbot&#39;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 窗口大小 小写的x，表示大小， 和位置</span><br><span class="line">root.geometry(&#39;720x400+500+200&#39;)</span><br><span class="line"></span><br><span class="line"># 输入组件</span><br><span class="line"># 输入框</span><br><span class="line">username &#x3D; tkinter.Entry(root, font&#x3D;(&#39;微软雅黑&#39;, 20), bg&#x3D;&#39;red&#39;, fg&#x3D;&#39;blue&#39;)</span><br><span class="line">username.grid(row&#x3D;0, column&#x3D;0)</span><br><span class="line"></span><br><span class="line"># 密码输入</span><br><span class="line">password &#x3D; tkinter.Entry(root, show&#x3D;&#39;*&#39;, font&#x3D;(&#39;微软雅黑&#39;, 20))</span><br><span class="line">password.grid(row&#x3D;1, column&#x3D;0)</span><br><span class="line"></span><br><span class="line"># 加入信息循环</span><br><span class="line">root.mainloop()</span><br></pre></td></tr></table></figure>

<p><img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1290205718,2520373871&fm=15&gp=0.jpg"></p>

    </div>
</article>


                </div>
                <aside class="col-md-4 gal-left" id="sidebar">
    <!-- 此为sidebar的搜索框, 非搜索结果页面 -->
<aside id="sidebar-search">
    <div class="search hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <form class="form-inline clearfix" id="search-form" method="get"
              action="/search/index.html">
            <input type="text" name="s" class="form-control" id="searchInput" placeholder="搜索文章~" autocomplete="off">
            <button class="btn btn-danger btn-gal" type="submit">
                <i class="fa fa-search"></i>
            </button>
        </form>
    </div>
</aside>
    <aside id="sidebar-author">
    <div class="panel panel-gal" data-aos="flip-right" data-aos-duration="3000">
        <div class="panel-heading" style="text-align: center">
            <i class="fa fa-quote-left"></i>
            esy
            <i class="fa fa-quote-right"></i>
        </div>
        <div class="author-panel text-center">
            <img src="/imgs/avatar.jpg" width="140" height="140"
                 alt="个人头像" class="author-image">
            <p class="author-description"><p>esy</p>
</p>
        </div>
    </div>
</aside>
    
    <aside id="sidebar-recent_comments">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-comments"></i>
            最新评论
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush"></ul>
    </div>
</aside>
    
    <!-- 要配置好leancloud才能开启此小工具 -->
    
    
    <aside id="sidebar-recent_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            近期文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%98%E6%B3%95/">最小二乘法</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E7%BB%9F%E8%AE%A1%E5%AD%A6%E4%B9%A0-%E7%AC%AC%E4%B8%80%E7%AB%A0/">统计学习--第一章</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/04/python%20work/hello-world/">Hello World</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/03/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%AF%84%E4%BC%B0%E6%8C%87%E6%A0%87/">分类模型的评估指标</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/10/21/python%20work/10-21-%E7%88%AC%E8%99%AB%E5%9F%BA%E7%A1%80/">10-21 爬虫基础</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/CRF%E7%9A%84%E6%95%B4%E4%BD%93%E6%B5%81%E7%A8%8B%E7%BB%93%E6%9E%9C/">CRF的整体流程结果</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/nlp-crf%E6%A8%A1%E5%9E%8B/">nlp_crf模型</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%983/">数学建模问题3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%982/">数学建模问题2</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%981/">数学建模问题1</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="sidebar-rand_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            随机文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/19/python%20work/Q-A-chatbot-%E7%AE%80%E5%8D%95%E5%AE%9E%E7%8E%B0/">Q&amp;A chatbot 简单实现</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/12/02/python%20work/hexo%E7%9A%84%E4%BD%BF%E7%94%A8/">LV-1.3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/11/24/python%20work/pyhon%E5%9F%BA%E7%A1%80-%E5%87%BD%E6%95%B0/">pyhon基础--函数</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/12/01/python%20work/python%E5%9F%BA%E7%A1%80%E4%B9%8B%E7%BB%98%E5%88%B6%E5%88%97%E8%A1%A8%E6%96%87%E4%BB%B6/">LV-1</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/08/08/python%20work/q-a%E6%95%B0%E6%8D%AE%E8%A1%A5%E5%85%85/">q&amp;a数据补充</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2019/12/10/python%20work/%E5%8D%87%E7%BA%A7conda/">升级conda</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/05/05/python%20work/%E5%9B%BE%E5%83%8F%E8%AF%86%E5%88%AB%E7%9A%84%E7%9B%AE%E6%A0%87/">图像识别的目标</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%983/">数学建模问题3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/08/python%20work/%E7%8A%B6%E6%80%81%E4%B8%BA3%E6%97%B6%E7%9A%84%E8%AE%BE%E5%AE%9A/">状态为3时的设定</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/08/31/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E7%9A%84%E7%A1%AE%E5%AE%9A/">分类模型的确定</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="gal-sets">
        <div class="panel panel-gal hidden-xs" data-aos="fade-up" data-aos-duration="2000">
            <ul class="nav nav-pills pills-gal">

                
                <li>
                    <a href="/2020/07/21/python%20work/python%E4%B8%8A%E7%9A%84GUI/index.html#sidebar-tags" data-toggle="tab" id="tags-tab">热门标签</a>
                </li>
                
                
                <li>
                    <a href="/2020/07/21/python%20work/python%E4%B8%8A%E7%9A%84GUI/index.html#sidebar-friend-links" data-toggle="tab" id="friend-links-tab">友情链接</a>
                </li>
                
                
                <li>
                    <a href="/2020/07/21/python%20work/python%E4%B8%8A%E7%9A%84GUI/index.html#sidebar-links" data-toggle="tab" id="links-tab">个人链接</a>
                </li>
                
            </ul>
            <div class="tab-content">
                
                <div class="cloud-tags tab-pane nav bs-sidenav fade" id="sidebar-tags">
    
    <a href="/tags/py-study/" style="font-size: 11.297993315343593px;" class="tag-cloud-link">py_study</a>
    
    <a href="/tags/nlp/" style="font-size: 11.660047370244424px;" class="tag-cloud-link">nlp</a>
    
    <a href="/tags/Graduation-work/" style="font-size: 17.852235583856633px;" class="tag-cloud-link">Graduation work</a>
    
    <a href="/tags/work/" style="font-size: 9.665720103504949px;" class="tag-cloud-link">work</a>
    
    <a href="/tags/hexo/" style="font-size: 18.936512132600637px;" class="tag-cloud-link">hexo</a>
    
    <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 18.286607841233504px;" class="tag-cloud-link">-个人博客搭建</a>
    
    <a href="/tags/malab-%E6%AF%95%E4%B8%9A/" style="font-size: 13.82224937173984px;" class="tag-cloud-link">-malab -毕业</a>
    
    <a href="/tags/python-%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/" style="font-size: 13.609869217034255px;" class="tag-cloud-link">-python -人工智能</a>
    
    <a href="/tags/python/" style="font-size: 15.804242152152456px;" class="tag-cloud-link">python</a>
    
    <a href="/tags/python/" style="font-size: 9.93268390514218px;" class="tag-cloud-link">-python</a>
    
    <a href="/tags/mathematical-modeling/" style="font-size: 9.895992259708603px;" class="tag-cloud-link">mathematical modeling</a>
    
    <a href="/tags/statistical-learning/" style="font-size: 16.29626087308197px;" class="tag-cloud-link">statistical learning</a>
    
</div>
                
                
                <div class="friend-links tab-pane nav bs-sidenav fade" id="sidebar-friend-links">
    
    <li>
        <a href="http://kdays.net/days/" target="_blank">KDays Forum</a>
    </li>
    
    <li>
        <a href="http://www.gal123.com/" target="_blank">绅士导航♂</a>
    </li>
    
    <li>
        <a href="http://www.moe123.com/" target="_blank">萌导航</a>
    </li>
    
</div>
                
                
                <div class="links tab-pane nav bs-sidenav fade" id="sidebar-links">
    
    <li>
        <a href="https://github.com/ZEROKISEKI/" target="_blank">Github</a>
    </li>
    
    <li>
        <a href="https://coding.net/u/SORA1" target="_blank">Coding</a>
    </li>
    
    <li>
        <a href="https://www.zhihu.com/people/aonosora/activities" target="_blank">知乎</a>
    </li>
    
</div>
                
            </div>
        </div>
    </aside>
    
</aside>
            </div>
        </div>
    </div>
    <footer id="gal-footer">
    <div class="container">
        Copyright © 2018 esy Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>.&nbsp;Theme by <a href="https://github.com/ZEROKISEKI" target="_blank">AONOSORA</a>
    </div>
</footer>

<!-- 回到顶端 -->
<div id="gal-gotop">
    <i class="fa fa-angle-up"></i>
</div>
</body>

<script src="/js/activate-power-mode.js"></script>

<script>

    // 配置highslide
	hs.graphicsDir = '/js/highslide/graphics/'
    hs.outlineType = "rounded-white";
    hs.dimmingOpacity = 0.8;
    hs.outlineWhileAnimating = true;
    hs.showCredits = false;
    hs.captionEval = "this.thumb.alt";
    hs.numberPosition = "caption";
    hs.align = "center";
    hs.transitions = ["expand", "crossfade"];
    hs.lang.number = '共%2张图, 当前是第%1张';
    hs.addSlideshow({
      interval: 5000,
      repeat: true,
      useControls: true,
      fixedControls: "fit",
      overlayOptions: {
        opacity: 0.75,
        position: "bottom center",
        hideOnMouseOut: true
      }
    })

    // 初始化aos
    AOS.init({
      duration: 1000,
      delay: 0,
      easing: 'ease-out-back'
    });

</script>
<script>
	POWERMODE.colorful = 'true';    // make power mode colorful
	POWERMODE.shake = 'true';       // turn off shake
	// TODO 这里根据具体情况修改
	document.body.addEventListener('input', POWERMODE);
</script>
<script>
    window.slideConfig = {
      prefix: '/imgs/slide/background',
      ext: 'jpg',
      maxCount: '6'
    }
</script>

<script src="/js/hs.js"></script>
<script src="/js/blog.js"></script>



<script src="/js/oni.js"></script>




</html>